export const debounce = (method, delay) => {
  let timer = null
  return function () {
    const context = this
    const args = arguments
    clearTimeout(timer)
    timer = setTimeout(function () {
      method.apply(context, args)
    }, delay)
  }
}

export let fontScale = 1

export const setRem = () => {
  const setRem = () => {
    const min = Math.min(
      (100 * document.documentElement.clientHeight) / 1080,
      (100 * document.documentElement.clientWidth) / 1920
    )
    fontScale = min / 100
    document.documentElement.style.fontSize = min + 'px'
  }
  window.addEventListener('resize', debounce(setRem, 200))
  setRem()
}
